package com.zy.qudadid.presenter;

import com.zy.qudadid.ui.view.StrokeView;

import android.util.Log;

import com.zy.bean.Dingdan;
import com.zy.qudadid.model.Res;
import com.zy.qudadid.model.Stroke;
import com.zy.qudadid.model.StrokeBean;
import com.zy.qudadid.network.Const;
import com.zy.qudadid.network.Net;
import com.zy.qudadid.presenter.base.BasePresenterImp;
import com.zy.qudadid.ui.view.StrokeView;
import com.zy.qudadid.utils.ToolsUtil;

import java.util.ArrayList;

import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by ASUS on 2017/3/21.
 */

public class StrokePresenter extends BasePresenterImp<StrokeView> {
    //查询登录用户的订单（司机或乘客各种状态及所有）
    public void Stroke(String data) {
        Subscription subscription = Net.getService()
                .Stroke(data)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Res<ArrayList<StrokeBean>>>() {

                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e("onError", "获取订单出错:" + e.getMessage().toString());
                        //   ToolsUtil.print("----", "获取订单出错:" + e.getMessage().toString());
                    }

                    @Override
                    public void onNext(Res<ArrayList<StrokeBean>> res) {
                        if (res.code == Const.OK) {
                          //  view.StrokeSuccess(res.datas.get(0));
                            view.StrokeSuccess(res.datas);
                            Log.e("onNext", "获取订单成功");
                        } else {
                            view.StrokeError(res.message);
                            Log.e("onNext", "获取订单出错:" + res.message);
                        }
                    }
                });

        addSubscription(subscription);
    }
}


